function jsonParse(str: string) {
  try {
    return JSON.parse(str);
  } catch (err) {
    return '';
  }
}

export function storeRemoteConfigure(content: string) {
  localStorage.setItem('teemo-remote-config', content);
}

export function getStoredRemoteConfigure() {
  const conf = localStorage.getItem('teemo-remote-config');
  if (conf) return jsonParse(conf);
  return null;
}

export function getUsername() {
  const username = localStorage.getItem('teemo-configure-username');
  return username || '';
}

export function storeSitesVisible(visible: boolean) {
  localStorage.setItem('teemo-sites-visible', String(visible));
}

export function getSitesVisible() {
  const val = localStorage.getItem('teemo-sites-visible');
  return val === 'true' ? true : false;
}
